package collection_try;

import java.util.*;

public class ArrayDequeTest {
    public static void main(String[] args) {
//        stack:先进后出 push进，pop出，peek查头
        System.out.println("stack:");
        Deque<Integer> st = new ArrayDeque<>();
        st.push(1);
        st.push(2);
        st.push(3);
        st.push(4);
        st.push(5);
        System.out.println(st);
        System.out.println("利用pop移除栈首："+st.pop());
        System.out.println(st);
        System.out.println(st.peek());

        for(int n:st){
            System.out.print(n);
        }

        Object[] arr = st.toArray();
        
        for(Object i:arr){
            System.out.println(i);
        }

//        queue:先进先出 offer进poll出
        System.out.println();
        System.out.println("queue:");
        Deque<Integer> qe = new ArrayDeque<>();
        qe.offer(1);
        qe.offer(2);
        qe.offer(3);
        qe.offer(4);
        qe.offer(5);
        System.out.println(qe);
        System.out.println("利用poll移除队首："+qe.poll());
        System.out.println(qe);
        System.out.println(qe.peek());
        for(int n:qe){
            System.out.print(n);
        }

    }
}
